using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
using System;

namespace Microsoft.SqlServer.Management.SqlManagerUI.Scripting
{
	internal abstract class ScriptCommand
	{
		public abstract void Script(Urn objectToScript, ScriptingOptions scriptOptions);

		protected Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo GetObjectInfo(SqlSmoObject smoObject)
		{
			string type;
			switch (type = smoObject.Urn.Type)
			{
			case "Table":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((Table)smoObject).Name, smoObject.Urn, ((Table)smoObject).Schema);
			case "XmlSchemaCollection":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((XmlSchemaCollection)smoObject).Name, smoObject.Urn, ((XmlSchemaCollection)smoObject).Schema);
			case "UserDefinedFunction":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((UserDefinedFunction)smoObject).Name, smoObject.Urn, ((UserDefinedFunction)smoObject).Schema);
			case "Role":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((DatabaseRole)smoObject).Name, smoObject.Urn);
			case "User":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((User)smoObject).Name, smoObject.Urn);
			case "FullTextCatalog":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((FullTextCatalog)smoObject).Name, smoObject.Urn);
			case "UserDefinedDataType":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((UserDefinedDataType)smoObject).Name, smoObject.Urn, ((UserDefinedDataType)smoObject).Schema);
			case "SqlAssembly":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((SqlAssembly)smoObject).Name, smoObject.Urn);
			case "ApplicationRole":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((ApplicationRole)smoObject).Name, smoObject.Urn);
			case "DdlTrigger":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((DatabaseDdlTrigger)smoObject).Name, smoObject.Urn);
			case "StoredProcedure":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((StoredProcedure)smoObject).Name, smoObject.Urn, ((StoredProcedure)smoObject).Schema);
			case "View":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((View)smoObject).Name, smoObject.Urn, ((View)smoObject).Schema);
			case "Default":
				if (smoObject is DefaultConstraint)
				{
					return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((DefaultConstraint)smoObject).Name, smoObject.Urn);
				}
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((Default)smoObject).Name, smoObject.Urn);
			case "Check":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((Check)smoObject).Name, smoObject.Urn);
			case "Rule":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((Rule)smoObject).Name, smoObject.Urn, ((Rule)smoObject).Schema);
			case "Synonym":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((Synonym)smoObject).Name, smoObject.Urn, ((Synonym)smoObject).Schema);
			case "UserDefinedType":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((UserDefinedType)smoObject).Name, smoObject.Urn, ((UserDefinedType)smoObject).Schema);
			case "UserDefinedAggregate":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((UserDefinedAggregate)smoObject).Name, smoObject.Urn, ((UserDefinedAggregate)smoObject).Schema);
			case "UserDefinedTableType":
				return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo(((UserDefinedTableType)smoObject).Name, smoObject.Urn, ((UserDefinedTableType)smoObject).Schema);
			}
			return new Microsoft.SqlServer.Management.SqlManagerUI.ObjectInfo("", smoObject.Urn);
		}
	}
}
